2015-10-06(腾工).sql 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePiece')
  2. BEGIN
  3. DROP VIEW [dbo].BView_DoorCityTotakePiece
  4. END
  5. GO
  6. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePiece]'))
  7. EXEC dbo.sp_executesql @statement = N'
  8. CREATE VIEW [dbo].[BView_DoorCityTotakePiece]
  9. AS
  10. SELECT
  11. tb_ErpOrder.ID,
  12. dbo.tb_ErpOrder.Ord_DividedShop,
  13. dbo.tb_ErpOrder.Ord_Number,
  14. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  15. Ordv_DigitalNumber,
  16. Ord_Type,
  17. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  18. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  19. Cus_Name AS 客户姓名,
  20. Cus_Name_py AS 客户拼音,
  21. Cus_Sex_cs AS 客户性别,
  22. Cus_Telephone AS 客户电话,
  23. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  24. dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音,
  25. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  26. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  27. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  28. (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称,
  29. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中''
  30. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态,
  31. dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  32. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  33. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期,
  34. dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  35. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  36. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期,
  37. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'' and OPlist_CompletedStatus = ''1'')>0 then ''未完'' else
  38. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'') > 0 then ''未完'' else
  39. (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'') > 0 then ''OK'' else '''' end )end )end ) AS 是否完成,
  40. --(select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期,
  41. --(select top 1 OPlist_PickupTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期查询,
  42. tb_ErpOrderProductList.ID AS OPID,
  43. OPlist_ProdName AS 商品名称,
  44. dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急,
  45. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 预约取件日期,
  46. OPlist_ReservationTakeTime AS 预约取件日期查询,
  47. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS 商品取走日期,
  48. OPlist_PickupTime AS 商品取走日期查询,
  49. OPlist_SendVendor AS 是否发出,
  50. dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) AS 是否返工,
  51. dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 商品完成状态,
  52. dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 是否取走
  53. ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount
  54. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  55. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number
  56. Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber
  57. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  58. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'')
  59. '
  60. GO
  61. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed')
  62. BEGIN
  63. DROP VIEW [dbo].BView_CameraControlBookMainPhotographed
  64. END
  65. GO
  66. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed]'))
  67. EXEC dbo.sp_executesql @statement = N'
  68. CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed]
  69. AS
  70. SELECT tb_ErpOrder.ID,
  71. dbo.tb_ErpOrder.Ord_DividedShop,
  72. Ord_Type,
  73. dbo.tb_ErpOrdersPhotography.ID AS VID,
  74. dbo.tb_ErpOrder.Ord_Number,
  75. dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  76. Ordv_DigitalNumber,
  77. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  78. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  79. Cus_Name AS 客户姓名,
  80. Cus_Sex_cs AS 客户性别,
  81. Cus_Telephone AS 客户电话,
  82. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期,
  83. (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人,
  84. dbo.fn_GetOrderArrears(Ord_Number) AS 欠款,
  85. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  86. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  87. dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称,
  88. Ordpg_ApparelQuantity AS 服装套数,
  89. dbo.fn_CheckPhotographyStatus(Ordpg_PhotographyStatus) AS 拍摄状态,
  90. dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime) AS 摄影时间,
  91. Ordpg_ReservationPhotographyTime AS 摄影时间查询,
  92. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师,
  93. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理,
  94. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师,
  95. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理,
  96. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师,
  97. dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 录入备注,
  98. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Dispatcher) AS 安排人,
  99. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_DispatchTime)) AS 安排时间,
  100. (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN
  101. dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  102. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  103. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  104. dbo.tb_ErpOrdersPhotography ON
  105. dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber
  106. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  107. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2''))
  108. '
  109. GO
  110. if not exists
  111. (select * from syscolumns where id=object_id('tb_ErpOrdersPhotography') and name='Ordpg_SightsRemark')
  112. begin
  113. alter table tb_ErpOrdersPhotography add Ordpg_SightsRemark nvarchar(800) NULL
  114. end
  115. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpOrdersPhotography', N'COLUMN',N'Ordpg_SightsRemark'))
  116. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'景点备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpOrdersPhotography', @level2type=N'COLUMN',@level2name=N'Ordpg_SightsRemark'
  117. GO
  118. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityOpenOrderFriendSelect')
  119. BEGIN
  120. DROP VIEW [dbo].BView_DoorCityOpenOrderFriendSelect
  121. END
  122. GO
  123. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityOpenOrderFriendSelect]'))
  124. EXEC dbo.sp_executesql @statement = N'
  125. CREATE VIEW [dbo].[BView_DoorCityOpenOrderFriendSelect]
  126. AS
  127. SELECT
  128. dbo.tb_ErpCustomer.ID,
  129. Cus_CustomerNumber,
  130. Cus_Type,
  131. Cus_Name,
  132. Cus_NamePinyin,
  133. Cus_Telephone,
  134. Cus_Sex,
  135. Mc_CradNumber
  136. FROM dbo.tb_ErpCustomer LEFT OUTER JOIN
  137. dbo.tb_ErpMemberCard ON
  138. Cus_CustomerNumber = Mc_CustomerNumber AND
  139. Mc_CradNumber <> ''''
  140. '
  141. GO
  142. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberMain_GoldMember')
  143. BEGIN
  144. DROP VIEW [dbo].BView_MemberMain_GoldMember
  145. END
  146. GO
  147. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberMain_GoldMember]'))
  148. EXEC dbo.sp_executesql @statement = N'
  149. CREATE VIEW [dbo].[BView_MemberMain_GoldMember]
  150. AS
  151. SELECT Cus_ID, ID AS Mc_ID,
  152. Mc_Status,
  153. Mc_Number,
  154. Mc_CradNumber AS 会员卡号,
  155. Cus_Name AS 姓名,
  156. Cus_CustomerNumber AS 姓名编号,
  157. dbo.fn_CheckSex(Cus_Sex) AS 性别,
  158. Cus_Telephone AS 电话,
  159. Mc_CardType AS 类型,
  160. dbo.fn_GetMember(Mc_Number, 1) AS 积分,
  161. Mc_Money AS 金额,
  162. dbo.fn_GetMember(Mc_Number, 2) AS 折扣,
  163. dbo.fn_GetMember(Mc_Number, 3) AS 套系金额,
  164. dbo.fn_GetMember(Mc_Number, 4) AS 已返金额,
  165. dbo.fn_GetMember(Mc_Number, 5) AS 已取出金额,
  166. (SELECT COUNT(Mcse_ServiceCount) AS Expr1 FROM dbo.tb_ErpMemberCardServiceContent WHERE (Mcse_Number = dbo.BView_MemberCard.Mc_Number)) AS 服务次数,
  167. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''积分副卡'')) AS 积分副卡,
  168. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_2 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''现金副卡'')) AS 现金副卡,
  169. (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_1 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''返现副卡'')) AS 返现副卡,
  170. Mc_Remark AS 备注,
  171. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Mc_CreateDatetime)) AS 办卡日期
  172. FROM dbo.BView_MemberCard
  173. WHERE (Mc_Status = ''1'')
  174. '
  175. GO
  176. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthReworkStatistic')
  177. BEGIN
  178. DROP VIEW [dbo].BView_DoorCityTotakePieceMonthReworkStatistic
  179. END
  180. GO
  181. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]'))
  182. EXEC dbo.sp_executesql @statement = N'
  183. CREATE VIEW [dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]
  184. AS
  185. SELECT
  186. tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, tb_ErpOrderProductList_1.ID AS PPID,
  187. dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber,
  188. Ordv_DigitalNumber,
  189. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  190. CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  191. Cus_Name AS 客户姓名,
  192. Cus_Name_py AS 客户拼音,
  193. Cus_Sex_cs AS 客户性别,
  194. Cus_Telephone AS 客户电话,
  195. tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称,
  196. tb_ErpOrderProductList_1.OPlist_Class,
  197. (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别,
  198. tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出,
  199. dbo.fn_CheckProductReworkStatus(tb_ErpOrderProductList_1.OPlist_ReworkStatus)
  200. + CASE OPlist_ReworkRemark WHEN '''' THEN '''' ELSE ''/['' + OPlist_ReworkRemark + '']'' END AS 是否返工,
  201. OPlist_ReworkRemark2 AS 返工原因,
  202. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_ReworkTime)) AS 返工日期,
  203. tb_ErpOrderProductList_1.OPlist_ReworkTime AS 返工日期查询,
  204. dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成,
  205. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期,
  206. (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList
  207. WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount
  208. FROM dbo.tb_ErpOrder LEFT OUTER JOIN
  209. dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN
  210. dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON
  211. tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber
  212. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  213. WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'')
  214. '
  215. GO